<?php
 
interface Middleware {
    public static function go(Closure $next, $p);
}
 
class testOne implements Middleware {

    public static function go(Closure $next, $p)
    {
        echo "测试一" . $p . "\n";
        $next(++$p);
        echo "测试一后" . $p . "\n";
    }
}
 
class testTwo implements Middleware {
    public static function go(Closure $next, $p)
    {
        echo "测试二" . $p . "\n";
        $next(++$p);
        echo "测试二后" . $p . "\n";
    }
}
 
 
function goFun() {

    return function ($f, $className) {
        return function ($p) use ($f, $className) {
            $res = $className::go($f, $p);
        };
    };

}
 
$steps = ['testOne', 'testTwo'];
$prepare = function ($p) {
    echo "我是要做的操作" . $p . "\n";
};
// $go = array_reduce(array_reverse($steps), goFun(), $prepare);

$go = array_reduce(array_reverse($steps), function ($f, $className) {
    return function ($p) use ($f, $className) {
            $res = $className::go($f, $p);
        };
}, $prepare);

$go('666');